<?php


namespace app\admin\controller;


use think\Request;
use app\model\Config as ConfigModel;

class Config extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 全局副标题全局配置
     */
    public function couponSubtitle(Request $request)
    {
        $value = $request->param('brand_subtitle');
        if (!in_array($value, [ConfigModel::BRAND_SUBTITLE_QJ, ConfigModel::BRAND_SUBTITLE_ZDY])) {
            return fail('传参错误');
        }
        /**
         * @var ConfigModel $config
         */
        $config = ConfigModel::query()->where('type', 'coupon')->where('field', 'brand_subtitle')->find();
        if (!$config) {
            return fail('后台暂未配置，请联系技术');
        }
        $config->value = $value;
        $config->save();
        return success('设置成功', ['brand_subtitle' => $value]);
    }

    /**
     *  查询全局副标题全局配置
     */
    public function getCouponSubtitle()
    {
        /**
         * @var ConfigModel $config
         */
        $config = ConfigModel::query()->where('type', 'coupon')->where('field', 'brand_subtitle')->find();
        if (!$config) {
            return fail('后台暂未配置，请联系技术');
        }
        return success('查询成功', ['brand_subtitle' => $config->value]);
    }
}